<?php

namespace App\Http\Controllers\Admin;

use App\Models\Oncustomer;
use App\Models\Onorder;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class OnfreeorderController extends Controller
{
    public function __construct()
    {
        view()->share([
            '_orders' => 'am-in',
            '_onfree' => 'am-active',

        ]);

    }




    public function index(Request $request){

        $where = function ($query) use ($request) {
            if($request->has('order_no')and $request->order_no !=''){
                $search = "%".$request->order_no."%";
                $query->where('order_no','like',$search);
            }

            if($request->has('pay_at')and $request->pay_at !=""){
                $time = explode(" ~ ",$request->pay_at);
                $start = $time[0] . ' 00:00:00';
                $end = $time[1] . ' 23:59:59';
                $query->whereBetween('pay_at',[$start,$end]);
            }

        };

        $orders=Onorder::where('type',2)->where('is_pay',1)->where($where)->orderBy('pay_at','desc')->paginate(15);
        return view('admin.order.onfree',compact('orders'));
    }
}
